package com.sy.controller.finance;

import com.sy.bean.finance.FinanceBill;
import com.sy.bean.finance.param.FinancePage;
import com.sy.bean.finance.utils.BeanToMap;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.service.finance.FinanceBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/finance/bill")
@Api(tags = "finance-收支账单管理")
public class FinanceBillController extends MyFinanceBaseController {
    @Autowired
    FinanceBillService billService;

    @GetMapping("/{id}")
    @ApiOperation("获取支付单信息(根据id)")
    public ResultBean query(@PathVariable("id") Integer id) {
        return selectResult(billService.get(id));
    }

    @GetMapping("/page/fk")
    @ApiOperation("查询付款单(分页)")
    public ResultBean queryFK(@RequestBody FinancePage page) {
        Map map = BeanToMap.getMap(page);
        map.put("type",1);
        return selectResult(billService.query(map));
    }
    @GetMapping("/page/sk")
    @ApiOperation("查询收款单(分页)")
    public ResultBean querySK(@RequestBody FinancePage page) {
        Map map = BeanToMap.getMap(page);
        map.put("type",2);
        return selectResult(billService.query(map));
    }

    @PostMapping("/fk")
    @ApiOperation("新增付款单")
    public ResultBean saveFK(@RequestBody FinanceBill bill) {
        bill.setType(1);
        int rs = billService.save(bill);
        return saveResult(rs);
    }

    @PostMapping("/sk")
    @ApiOperation("新增收款单")
    public ResultBean saveSK(@RequestBody FinanceBill bill) {
        bill.setType(2);
        int rs = billService.save(bill);
        return saveResult(rs);
    }


}
